package com.ykj.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.unit.DataUnit;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ykj.dto.Result;
import com.ykj.entity.Plate;
import com.ykj.mapper.PlateMapper;
import com.ykj.service.PlateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Y2014188432
 * @since 2022-05-07
 */
@Service
public class PlateServiceImpl extends ServiceImpl<PlateMapper, Plate> implements PlateService {

    @Override
    public Result getHot() {
        List<Plate> list = query().last("limit 6").list();
        return Result.ok(list);
    }

    @Override
    public Result create(Plate plate) {
        // 1 设置创建日期
        String createTime = DateUtil.formatDateTime(new Date());
        // 2 装载
        plate.setCreateTime(createTime);
        // 3 新建
        save(plate);
        // 4 返回
        return Result.ok();
    }

    @Override
    public Result getAll() {
        // 1 查数据库
        List<Plate> plateList = query().list();
        // 2 返回
        return Result.ok(plateList);
    }
}
